import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:photo_frame/net/model/asset_trans_model.dart';
import 'package:photo_frame/pages/gallery/send_asset/widget/send_asset_record_widget.dart';
import 'package:photo_frame/utils/localization_util.dart';

class SendAssetItemWidget extends StatelessWidget {
  final AssetTransModel transModel;
  final void Function(AssetTransModel) resend;
  final void Function(AssetTransModel) delete;

  SendAssetItemWidget(
      {required this.transModel,
      required this.resend,
      required this.delete,
      super.key});

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Container(
          color: Colors.white,
          padding: EdgeInsets.only(left: 10, right: 15),
          child: Column(
            children: [
              SizedBox(
                height: 10,
              ),
              IntrinsicHeight(
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: [
                    buildFutureImage(transModel.assetId ?? "", 90, 90),
                    SizedBox(
                      width: 10,
                    ),
                    Expanded(
                      child: Column(
                        children: [
                          SizedBox(height: 8),
                          Row(children: [
                            Expanded(
                                child: Text(
                              "${transModel.toFrameName}",
                              style: TextStyle(
                                  fontSize: 13, fontWeight: FontWeight.w900),
                            )),
                            Text(
                              transModel.transStatus == 0
                                  ? appLocalForContext(context).uploading
                                  : transModel.transStatus == 1
                                      ? appLocalForContext(context)
                                          .uploadSuccess
                                      : appLocalForContext(context).uploadFail,
                              textAlign: TextAlign.left,
                              style: TextStyle(
                                  color: Color(transModel.transStatus == 0
                                      ? 0xff999999
                                      : transModel.transStatus == 1
                                          ? 0xff3F74EF
                                          : 0xffEC4040)),
                            )
                          ]),
                          Expanded(child: SizedBox()),
                          Row(children: [
                            Expanded(
                                child: Text(
                              DateFormat('yyyy/MM/dd').format(
                                DateTime.fromMillisecondsSinceEpoch(
                                  int.parse(transModel.transDate ??
                                      DateTime.timestamp()
                                          .millisecondsSinceEpoch
                                          .toString()),
                                ),
                              ),
                            )),
                            CupertinoButton(
                                padding: EdgeInsets.zero,
                                onPressed: () {
                                  resend(transModel);
                                },
                                child: SizedBox(
                                  width: 40,
                                  height: 40,
                                  child: Align(
                                      alignment: Alignment.centerRight,
                                      child: transModel.transStatus == 2
                                          ? Image.asset(
                                              width: 20,
                                              height: 20,
                                              "images/icon_asset_resend.png")
                                          : SizedBox()),
                                )),
                            CupertinoButton(
                                padding: EdgeInsets.zero,
                                onPressed: () {
                                  delete(transModel);
                                },
                                child: SizedBox(
                                  width: 40,
                                  height: 40,
                                  child: Align(
                                      alignment: Alignment.centerRight,
                                      child: transModel.transStatus == 2
                                          ? Image.asset(
                                              width: 20,
                                              height: 20,
                                              "images/icon_asset_record_delete.png")
                                          : SizedBox()),
                                )),
                          ])
                        ],
                      ),
                    )
                  ],
                ),
              ),
              SizedBox(
                height: 20,
              ),
            ],
          ),
        ),
        Positioned(
            bottom: 0,
            left: 0,
            right: 0,
            child: Container(
              color: Color(0xfff2f2f2),
              height: 10,
            )),
        Positioned(
            left: 0,
            bottom: 10,
            child: Container(
              height: 2,
              width: transModel.transStatus == 0
                  ? MediaQuery.of(context).size.width * transModel.progress
                  : 0,
              color: Color(0xff3f74ef),
            ))
      ],
    );
  }
}
